package biz.inspeed.test.mina.m2;

import org.apache.mina.core.service.IoHandler;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import biz.inspeed.test.tool.CommonUtil;

public class MinaIoHandler implements IoHandler
{
//	Log log = LogFactoryImpl.getLog(getClass());
	private static final Logger log = LoggerFactory.getLogger("socket");
	@Override
	public void sessionCreated ( IoSession session ) throws Exception
	{
		log.debug ( "创建了一个连接" + session.getRemoteAddress ().toString () );
		System.out.println("创建了一个连接" + session.getRemoteAddress ().toString () );
		
	}

	@Override
	public void sessionOpened ( IoSession session ) throws Exception
	{
		log.debug ( "打开了一个连接" + session.getRemoteAddress ().toString () );
		System.out.println("打开了一个连接" + session.getRemoteAddress ().toString ());
	}

	@Override
	public void sessionClosed ( IoSession session ) throws Exception
	{
		log.debug ( "关闭了一个连接" + session.getRemoteAddress ().toString () );
		System.out.println("关闭了一个连接" + session.getRemoteAddress ().toString ());
	}

	@Override
	public void sessionIdle ( IoSession session , IdleStatus status ) throws Exception
	{
		log.debug ( "现在是空闲状态" );
		System.out.println( "现在是空闲状态" );
	}

	@Override
	public void exceptionCaught ( IoSession session , Throwable cause ) throws Exception
	{
		log.debug ( "遇到了一个异常-->" + cause );
		System.out.println("遇到了一个异常-->" + cause );
	}

	@Override
	public void messageReceived ( IoSession session , Object message ) throws Exception
	{
			log.debug ( "<--收到的长度为收到-->" + message );
			System.out.println("<--收到的长度为收到-->" + message);
		
	}

	@Override
	public void messageSent ( IoSession session , Object message ) throws Exception
	{
		log.debug ( "<--MinaIoHandler--发送信息完成-->" + "@time:" +CommonUtil.getCurrentTime ());
		log.debug ( "<--MinaIoHandler--发送的是-->" + message.toString ());
		System.out.println( "<--MinaIoHandler--发送的是-->" + message.toString ());
	}

}
